//
//  Category_LabelView.m
//  MindBox
//
//  Created by MS on 16-1-5.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "Category_LabelView.h"
#import "CategoryGoodsCell.h"
#import "UIView+Frame.h"
@interface Category_LabelView ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>



@end

@implementation Category_LabelView
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        UICollectionViewFlowLayout * viewLayout = [[UICollectionViewFlowLayout alloc] init];
        viewLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        viewLayout.minimumLineSpacing = 10;
        viewLayout.minimumInteritemSpacing = 0;

        
        UICollectionView * collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:viewLayout];
        self.collectionView = collectionView;
        collectionView.contentInset = UIEdgeInsetsMake(20, 0, 64, 0);
        collectionView.delegate = self;
        collectionView.dataSource = self;
        collectionView.alwaysBounceVertical = YES;
        collectionView.backgroundColor = [UIColor whiteColor];
        [self addSubview:collectionView];
        
    }
    return self;
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.category_labels.count;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    Category_Label * lists =self.category_labels[section];
    
    return lists.label_list.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    Category_Label * lists =self.category_labels[indexPath.section];
    Label_List * list = lists.label_list[indexPath.item];
    
    CategoryGoodsCell * cell = [CategoryGoodsCell cellWithcollectionView:collectionView cellForItemAtIndexPath:indexPath];
   
    cell.label_list =list;
    cell.changeImageStyle = YES;
    
    return cell;
}


-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake((self.width - 60)/3, 120);
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 15, 0, 15);
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    Category_Label * lists =self.category_labels[indexPath.section];
    Label_List * list = lists.label_list[indexPath.item];
    
    if ([self.delegate respondsToSelector:@selector(CategoryLabelViewDidClick:list:index:)]) {
        
        [self.delegate CategoryLabelViewDidClick:self list:list index:indexPath.item];
        
    }
    
}



@end
